<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Log;
use Org\Util\Page;
 

class MailinglistController extends BaseController {
  //邮件列表
  public function email(){
        /* $lie = M('mailing_list');
     	$sql = $lie->select(); 
        $this->assign("sql",$sql);
        $this->display(); */
		$m=M("mailing_list");
		$keywords=I("param.keywords");
		//$wheres['delete']="";
		if(I("param.listrows"))
		{
			$where['listrows']=I("param.listrows");

		}
		if($keywords)
		{
			$wheres['mailing_address|mail_name|types']=array('like',"%".trim($keywords)."%");
		}
		
		$where['where']=$wheres;
		$where['order']="email_id desc";
		$results = $this->_getListsViewSpecial($m, $where);
		$this->assign("sql",$results['lists']);
		$this->assign("show",$results['page_html']);
		$this->display();
  }
 public function add(){
        $email_id = I('email_id');

        $email_id = intval($email_id);
       // $email_id = empty($email_id)?$0:$email_id;
        if($email_id>0)
          $rel = M('mailing_list')->where('email_id='.$email_id)->find();

         $this->assign('email',$rel);
         $this->display();
          }
public function edit(){
     $data = $_POST;

     //$data['adminuser'] = UID;
	 $data ["adminuser"]=$_SESSION['admin_name'];
     $data["add_time"] = date("Y-m-d H:i:s");
     $data["type"] = rtrim($_POST['types'][0].",".$_POST['types'][1],",");
	// var_dump($data);
	 //exit;
  if (empty($_POST["email_id"])||$_POST["email_id"] == 0) {
      unset ( $data ["email_id"] );
      $result = M ( "mailing_list" )->add ( $data );
    } else {
      $data ["email_id"] = $data ["email_id"]; 
      $result = M ( "mailing_list" )->save ( $data );
    }

    if($result){
      $this->success ( "操作成功!");
    }else{
    $this->error ( "操作失败!");
    }
}


//删除
public function det(){
        $id = I("get.email_id");
          
        $shanchu = M("mailing_list");
        $bool = $shanchu->delete($id);
          
        if($bool){
          $this->success("删除成功");
        }else{
          $this->error("没有数据删除失败");
        }
}


}


?>	